define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	require("../../myscripts/SystemConfig");
	// var fn = require("$UI/ls_common/fn");
	var Model = function() {
		this.callParent();
	};

	Model.prototype.modelParamsReceive = function(event) {
		console.log("modelParamsRecive()");
		this.CustomerApi("FXS_LV1_Data", "1", "0");
	};
	Model.prototype.CustomerApi = function(data_name, res_Type, res_CtmID) {
		console.log("CustomerApi()");
		var api_url = window.app.base_url + window.app.CustomerListApi;
		var data = {};
		data.username = window.app.username;
		data.password = window.app.password;
		data.Type = res_Type;
		data.CtmID = res_CtmID;
		var self = this;
		$.ajax({
			type : "POST",
			url : require.toUrl(api_url),
			data : {
				'data' : JSON.stringify(data)
			},
			dataType : 'json',
			success : function(res) {
				console.log(res);
				window.app.CustomerApi_ret = res;
				self.comp(data_name).clear();
				self.comp(data_name).loadData(res);
				return;
			},
			error : function(e) {
				justep.Util.hint("网络出错，无法获取下级分销商信息。");
				return;
			}
		});
	};
	Model.prototype.ExitBtnClick = function(event) {
		justep.Shell.showPage("TypeSelect");
	};

	Model.prototype.LV1_Next_btnClick = function(event) {
		console.log(event.bindingContext.$object);
		var CtmID = event.bindingContext.$object.val('CtmID');
		this.CustomerApi("FXS_LV2_Data", "2", CtmID.toString());
		this.comp("contents1").to("LV2_Content");
	};

	Model.prototype.LV3_Next_btnClick = function(event) {

	};

	Model.prototype.LV1_ContentActive = function(event) {
		console.log("LV1_ContentActive");

	};

	Model.prototype.LV2_ContentActive = function(event) {
		console.log("LV2_ContentActive");
	};

	Model.prototype.ToLV1_btnClick = function(event) {
		this.comp("contents1").to("LV1_Content");
	};

	Model.prototype.LV2_Next_btnClick = function(event) {
		var CtmID = event.bindingContext.$object.val('CtmID');
		this.CustomerApi("FXS_LV3_Data", "3", CtmID.toString());
		this.comp("contents1").to("LV3_Content");
	};

	Model.prototype.ToLV2_btnClick = function(event) {
		this.comp("contents1").to("LV2_Content");
	};

	Model.prototype.SaleLog_btnClick = function(event) {
		var CtmNo = event.bindingContext.$object.val('CtmNo');
		var Content = this.comp("contents1").getActiveXid();
		console.log("Content=", Content);
		this.comp("SalesAndInventContainer").load("Factory/Distributor/SalesAndInvent.w", {
			CtmNo : CtmNo,
			Content : Content
		});
	};

	return Model;
});